﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 摄像机跟随角色移动
/// </summary>
public class CameraFollow : MonoBehaviour {

    private Transform m_transform;
    private Transform m_player;

    public bool startfollow = false;

    private Vector3 normalPos;

    void Start()
    {
        m_transform = gameObject.GetComponent<Transform>();
        m_player = GameObject.Find("Player").GetComponent<Transform>();
        normalPos = m_transform.position;      
    }
	
    void Update()
    {        
        CameraMove();       
    }

    void CameraMove()
    {
        if (startfollow)
        {
            Vector3 nextPos = new Vector3(m_transform.position.x, m_player.position.y + 2.08f, m_player.position.z);
            m_transform.position = Vector3.Lerp(m_transform.position,nextPos,Time.deltaTime);
        }
    }	

    public void ResetCamera()
    {
        m_transform.position = normalPos;
    }
}
